package cn.bx.bid.service;

import cn.bx.bid.dao.ProfessorDao;
import cn.bx.bid.entity.Page;
import cn.bx.bid.entity.Professor;
import cn.bx.bid.entity.WorkHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//M V C
//@Scope("prototype")
//@Transactional(readOnly = true)
@Service
public class ProfessorService {
	public static final int PAGE_SIZE = Page.PAGE_SIZE;

	@Autowired
	private ProfessorDao dao;
//	public int add(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.add(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int update(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.update(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int batchDel(long[] ids) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.batchDel(ids);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}


	public Page<Professor> paging(int pageNo, int limit, String name, String tele, String identityNumber) {

		List<Professor> list = dao.search(pageNo, limit, name, tele, identityNumber);
		int total = dao.searchTotal(name, tele, identityNumber);
		Page<Professor> p = new Page<Professor>(total, limit, list);
		return p;
	}

	public Professor get(long id) {
		return dao.get(id);
	}
	public int update(Professor p) {
		return dao.update(p);
	}


	public int batchDel(long[] ids) {
		return dao.delALL(ids);
	}

	public int add(Professor newPro) {
		return dao.add(newPro);
	}

	public WorkHistory getHistory(long id){
		return dao.getHistory(id);
	}
	public int historyUpdate(WorkHistory p) {
		return dao.updateWorkhistory(p);
	}
	public int delHis(long hisid) {
		return dao.delHis(hisid);
	}

	public int addHistory(WorkHistory w) {
		return dao.addHistory(w);
	}

	public WorkHistory getHistoryid(long id) {
		return dao.getHistoryid(id);
	}

	//查找专家参与过的项目
	public Professor projectGet(long id){
		return dao.projectGet(id);
	}


//	public User get(long id) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.get(id);
//
//		} finally {
//			MyBatisUtil.close(s);
//		}
//	}

}